home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1996 June / Software of the Month Club 1996 June.iso / pc / dos / dtp / display / util / pieces / vesainfo.c
Encoding:
C/C++ Source or Header  |  1995-10-27  |  6.1 KB  |  174 lines

  1. /**
  2.  ** VESAINFO.H ---- routines to retrieve info from the VESA BIOS
  3.  **
  4.  ** Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5.  ** Copyright (C) 1992 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
  6.  ** Copyright (C) 1993 Grzegorz Mazur, gbm@ii.pw.edu.pl
  7.  ** Modified by Jih-Shin Ho to support VESA 2.0
  8.  **
  9.  ** This file is distributed under the terms listed in the document
  10.  ** "copying.dj", available from DJ Delorie at the address above.
  11.  ** A copy of "copying.dj" should accompany this file; if not, a copy
  12.  ** should be available from where this file was obtained.  This file
  13.  ** may not be distributed without a verbatim copy of "copying.dj".
  14.  **
  15.  ** This file is distributed WITHOUT ANY WARRANTY; without even the implied
  16.  ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17.  **/
  18.  
  19. /*
  20.  * VESA BIOS extended function number and return code
  21.  */
  22. #define VESA_FUNC    0x4f00
  23. #define VESA_SUCCESS    0x004f
  24.  
  25. #define VESA_VERSION(major,minor)    ((((major) & 0xff) << 8) | ((minor) & 0xff))
  26. #define VESA_VERSION_MAJOR(vers)    (((vers) >> 8) & 0xff)
  27. #define VESA_VERSION_MINOR(vers)    ((vers) & 0xff)
  28.  
  29. /*
  30.  * VESA BIOS sub-function numbers
  31.  */
  32. #define VESA_VGA_INFO    0        /* get VGA adapter info */
  33. #define VESA_MODE_INFO  1        /* get SVGA mode info */
  34. #define VESA_SET_MODE    2        /* set video mode */
  35. #define VESA_GET_MODE    3        /* get current video mode */
  36. #define VESA_VGA_STATE  4        /* save/restore VGA state */
  37. #define VESA_PAGE_CTL    5        /* memory control */
  38. /* VESA 1.1 +++ */
  39. #define VESA_SCAN_LNLEN 6        /* set/get scan line length */
  40. #define VESA_DISP_START 7        /* set/get display start address */
  41. /* VESA 1.2 +++ */
  42. #define VESA_PAL_CNTRL  8        /* DAC palette control */
  43.  
  44. /*
  45.  * The VGA info structure (without padding)
  46.  */
  47. typedef struct {
  48.     char        VESASignature[4];    /* should be "VESA" */
  49.     short        VESAVersion;    /* VESA version number */
  50.     char  far       *OEMStringPtr;    /* Pointer to OEM string */
  51.     long        Capabilities;    /* capabilities of the video env */
  52.     short far       *VideoModePtr;    /* ptr to supported Super VGA modes */
  53.     /*
  54.      * memory size in 64K blocks in VESA 1.2 and later
  55.      */
  56.     short        MemorySize;        /* # of 64K pages */
  57. } VgaInfoBlock;
  58.  
  59. /*
  60.  * The mode information structure (without padding)
  61.  */
  62. typedef struct {
  63.     short        ModeAttributes;    /* mode attributes */
  64.     char        WinAAttributes;    /* Window A attributes */
  65.     char        WinBAttributes;    /* Window B attributes */
  66.     short        WinGranularity;    /* window granularity */
  67.     short        WinSize;        /* window size */
  68.     unsigned short  WinASegment;    /* Window A start segment */
  69.     unsigned short  WinBSegment;    /* Window B start segment */
  70.     void     far   (*WinFuncPtr)();    /* pointer to window function */
  71.     short        BytesPerScanLine;    /* bytes per scan line */
  72.     /*
  73.      * extended information
  74.      * optional information
  75.      */
  76.     short        XResolution;    /* horizontal resolution */
  77.     short        YResolution;    /* vertical resolution */
  78.     char        XCharSize;        /* character cell width */
  79.     char        YCharSize;        /* character cell height */
  80.     char        NumberOfPlanes;    /* number of memory planes */
  81.     char        BitsPerPixel;    /* bits per pixel */
  82.     char        NumberOfBanks;    /* number of banks */
  83.     char        MemoryModel;    /* memory model type */
  84.     char        BankSize;        /* bank size in K */
  85.     char        NumImagePages;    /* number of image pages */
  86.     char        reserved[1];
  87.     /*
  88.      * VESA 1.2 and later
  89.      */
  90.     char        RedMaskSize;    /* number of bits in red mask */
  91.     char        RedMaskPos;        /* starting bit for red mask */
  92.     char        GreenMaskSize;
  93.     char        GreenMaskPos;
  94.     char        BlueMaskSize;
  95.     char        BlueMaskPos;
  96.     char        ReservedMaskSize;    /* reserved bits in pixel */
  97.     char        ReservedMaskPos;
  98.     char        DirectScreenMode;
  99.     /*
  100.      * VESA 2.0 and later
  101.      */
  102.     unsigned long   PhysBasePtr;
  103.     unsigned long   OffScreenMemOffset;
  104.     unsigned short  OffScreenMemSize;
  105. } ModeInfoBlock;
  106.  
  107. /*
  108.  * MODE attribute bits
  109.  */
  110. #define MODE_SUPPORTED  1        /* Mode supported in hardware */
  111. #define MODE_EXTINFO    2        /* Extended information available */
  112. #define MODE_SUPBIOS    4        /* Text output supported by BIOS */
  113. #define MODE_ISCOLOR    8        /* Monochrome/color mode */
  114. #define MODE_ISGRAPHICS 16        /* Mode type (0: text, 1:graphics) */
  115. #define MODE_NO_WINDOW  0x40            /* No windowed memory mode */
  116. #define MODE_LINEAR_FRAME 0x80         /* Support Linear frame buffer */
  117.  
  118. /*
  119.  * Window attribute bits
  120.  */
  121. #define WIN_SUPPORTED    1        /* Window supported */
  122. #define WIN_READABLE    2        /* Window readable */
  123. #define WIN_WRITABLE    4        /* Window writable */
  124.  
  125. /*
  126.  * MemoryModel values
  127.  */
  128. #define MODEL_TEXT    0        /* 00h = Text mode */
  129. #define MODEL_CGA    1        /* 01h = CGA graphics */
  130. #define MODEL_HERC    2        /* 02h = Hercules graphics */
  131. #define MODEL_4PLANE    3        /* 03h = 4-plane planar */
  132. #define MODEL_PACKED    4        /* 04h = Packed pixel */
  133. #define MODEL_256_NC    5        /* 05h = Non-chain 4, 256 color */
  134. #define MODEL_DIRECT    6        /* 06h = direct color mode */
  135. /* 07h-0Fh = Reserved, to be defined by VESA */
  136. /* 10h-FFh = To be defined by OEM         */
  137.  
  138. union {
  139.     VgaInfoBlock  _vgainfo;
  140.     ModeInfoBlock _modeinfo;
  141.     char      _safety_buffer[256];
  142. } VESAinfoBlock;
  143. int VESAversion = 0;
  144.  
  145. VgaInfoBlock *VESAgetInfo(void)
  146. {
  147.     _ES = FP_SEG(&VESAinfoBlock._vgainfo);
  148.     _DI = FP_OFF(&VESAinfoBlock._vgainfo);
  149.     _AX = VESA_FUNC + VESA_VGA_INFO;
  150.     geninterrupt(0x10);
  151.     if((_AX == VESA_SUCCESS) &&
  152.        (VESAinfoBlock._vgainfo.VESASignature[0] == 'V') &&
  153.        (VESAinfoBlock._vgainfo.VESASignature[1] == 'E') &&
  154.        (VESAinfoBlock._vgainfo.VESASignature[2] == 'S') &&
  155.        (VESAinfoBlock._vgainfo.VESASignature[3] == 'A')) {
  156.         VESAversion = VESAinfoBlock._vgainfo.VESAVersion;
  157.         return(&VESAinfoBlock._vgainfo);
  158.     }
  159.     return(0);
  160. }
  161.  
  162. ModeInfoBlock *VESAgetModeInfo(int mode)
  163. {
  164.     _ES = FP_SEG(&VESAinfoBlock._modeinfo);
  165.     _DI = FP_OFF(&VESAinfoBlock._modeinfo);
  166.     _CX = mode;
  167.     _AX = VESA_FUNC + VESA_MODE_INFO;
  168.     geninterrupt(0x10);
  169.     if(_AX != VESA_SUCCESS) return(0);
  170.     if((VESAinfoBlock._modeinfo.ModeAttributes & MODE_SUPPORTED) == 0) return(0);
  171.     return(&VESAinfoBlock._modeinfo);
  172. }
  173.  
  174.